package com.sim.action;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;


import com.opensymphony.xwork2.ActionContext;
import com.sim.base.BaseAction;
import com.sim.domain.PsychologicalHealthType;
import com.sim.util.QueryHelper;
@Controller
@Scope("prototype")
@SuppressWarnings("serial")
public class PhtMAction extends BaseAction<PsychologicalHealthType> {
	/**
	 * true 表示升序<br>
	 * false 表示降序
	 */
	private boolean asc = true;
	//主页面
    public String list() throws Exception {
    	new QueryHelper(PsychologicalHealthType.class, "p")//
    	    .addOrderProperty(true, "p.id", asc) //  
    	    .preparePageBean(subsidizeService, pageNum, pageSize);		    
       
    	return "list";
    }
    /** 删除 */
	public String delete() throws Exception {
		phtService.delete(model.getId());
		return "toList";
	}

	/** 添加页面 */
	public String addUI() throws Exception {
		return "saveUI";
	}

	/** 添加 */
	public String add() throws Exception {
		phtService.save(model);
		return "toList";
	}

	/** 修改页面 */
	public String editUI() throws Exception {
		// 准备回显的数据
		PsychologicalHealthType forum = phtService.getById(model.getId());
		ActionContext.getContext().getValueStack().push(forum);
		return "saveUI";
	}

	/** 修改 */
	public String edit() throws Exception {
		// 1，从数据库中取出原对象
		PsychologicalHealthType forum = phtService.getById(model.getId());
		
		// 2，设置要修改的属性
		forum.setTitle(model.getTitle());
		forum.setDescription(model.getDescription());

		// 3，更新到数据库
		phtService.update(forum);

		return "toList";
	}
    
}
